<template>
  <el-button type="primary" @click="export2Excel">导出</el-button>
</template>

<script type="text/ecmascript-6">
  export default {
    props: {
      tHeader: {
        type: Array,
        default () {
          return []
        }
      },
      filterVal: {
        type: Array,
        default () {
          return []
        }
      },
      tableData: {
        type: Array
      }
    },
    methods: {
      export2Excel () {
        require.ensure([], () => {
          const {exportJsonToExcel} = require('vendor/Export2Excel')
          const tHeader = this.tHeader
          const filterVal = this.filterVal
          const list = this.tableData
          const data = this.formatJson(filterVal, list)
          exportJsonToExcel(tHeader, data, '列表excel')
        })
      },
      formatJson (filterVal, jsonData) {
        return jsonData.map(v => filterVal.map(j => v[j]))
      }
    }
  }
</script>

<style lang="less" ref="stylesheet/less" scoped>

</style>
